from .base_model import BaseModel
from django.contrib.auth.models import User
from .grade import Grade
from .semester import Semester
from django.db import models

class ClassInfo(BaseModel):
    """班级模型"""
    name = models.CharField(max_length=50, verbose_name="班级名称")
    grade = models.ForeignKey(Grade, on_delete=models.CASCADE, related_name='classes', verbose_name="年级")
    semester = models.ForeignKey(Semester, on_delete=models.CASCADE, related_name='classes', verbose_name="学期")
    homeroom_teacher = models.ForeignKey(
        User, 
        on_delete=models.SET_NULL, 
        null=True, 
        blank=True, 
        related_name='homeroom_classes',
        verbose_name="班主任"
    )
    assistants = models.ManyToManyField(User, blank=True, related_name='assistant_classes', verbose_name="班级小助手")

    def __str__(self):
        return f"{self.semester} {self.grade} {self.name}"

    class Meta:
        verbose_name = "班级信息"
        verbose_name_plural = "班级信息"
        unique_together = ('name', 'grade', 'semester')
     
    @classmethod
    def get_late_count(type='week'):
        """
        获取学生的迟到次数。

        :param student_id: 学生ID
        :return: 迟到次数
        """
        pass
    @classmethod  
    def get_homework_count(type='week'):
        """
        获取学生的作业未交次数。

        :param student_id: 学生ID
        :return: 作业未交次数
        """
        pass
    @classmethod
    def get_warning(type='week'):

        """
        获取学生的预警情况。

        :param student_id: 学生ID
        :return: 预警情况
        """
        pass
